﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace MazeWars
{
    public class WindowManager
    {
        static WindowManager inst;
        Window[] windows;
        const int NUM_WINDOWS = 5;

        public WindowManager()
        {
            windows = new Window[NUM_WINDOWS];
            windows[Window.TITLE_WINDOW] = new TitleWindow();
            windows[Window.BATTLE_WINDOW] = new BattleWindow();
            windows[Window.CREATION_WINDOW] = new TreeCreationWindow();
            windows[Window.GAMEOVER_WINDOW] = new GameOverWindow();
            windows[Window.TUTORIAL_WINDOW] = new TutorialWindow();
        }

        public Window getActiveWindow()
        {
            foreach (Window w in windows)
            {
                if (w.Active)
                {
                    return w;
                }
            }

            return null;
        }

        public void loadWindowContent(ContentManager cm, Viewport vp)
        {
            foreach (Window w in windows)
            {
                w.setupWindow(cm, vp);
            }
        }

        public void changeWindow(int id)
        {
            getActiveWindow().Active = false;
            windows[id].Active = true;
            windows[id].loadWindow();
        }

        public static WindowManager instance()
        {
            if (inst == null)
            {
                inst = new WindowManager();
            }

            return inst;
        }
    }//End of class WindowManager
}
